home *** CD-ROM | disk | FTP | other *** search
- // Copyright (c)1995 Ray Dream, Inc. All Rights Reserved.
- /* $Id: COMDefS.cpp 1.8 1997/06/28 05:13:42 damien Exp $ */
-
- ////////////////////////////////////////////////////////////////////////
- // Deformer Example //
- //--------------------------------------------------------------------//
- // Implementation of the Deformer Interface //
- ////////////////////////////////////////////////////////////////////////
-
-
- #ifndef __COMDEFS__
- #include "COMDEFS.h"
- #endif
-
- #ifndef __DEFSDLL__
- #include "DEFSDLL.h"
- #endif
-
- #ifndef __3DCOFAIL__
- #include "3DCoFail.h"
- #endif
-
- #undef INTERFACE
- #define INTERFACE Deformer
- // Constructor / Destructor of the C++ Object :
- Deformer::Deformer() {
- fCRef=0; // Reference Counter
- // Data initialisation :
- fData.fAxis = kAxisZ;
- fData.fUBegScale = 1.0;
- fData.fUEndScale = 1.0;
- fData.fVBegScale = 1.0;
- fData.fVEndScale = 1.0;
- fData.fBoundingBox.fMin[0] = 0.0;
- fData.fBoundingBox.fMin[1] = 0.0;
- fData.fBoundingBox.fMin[2] = 0.0;
- fData.fBoundingBox.fMax[0] = 0.0;
- fData.fBoundingBox.fMax[1] = 0.0;
- fData.fBoundingBox.fMax[2] = 0.0;
- }
-
- Deformer::~Deformer() {
- global_count_Obj--;
- }
-
- // IUnknown Interface :
- HRESULT Deformer::QueryInterface(THIS_ REFIID riid,LPVOID* ppvObj) {
- *ppvObj=NULL;
-
- // The Deformer knows the interfaces of the parent Objects
- if (IsEqualIID(riid, IID_IUnknown))
- *ppvObj=(LPVOID)this;
- else if (IsEqualIID(riid, IID_I3DExDeformer2))
- *ppvObj=(LPVOID)(I3DExDeformer2*)this;
- else if (IsEqualIID(riid, IID_I3DExDataExchanger))
- *ppvObj=(LPVOID)(I3DExDataExchanger*)this;
- else if (IsEqualIID(riid, IID_I3DExtension))
- *ppvObj=(LPVOID)(I3DExtension*)this;
-
- // we must add reference if we return an interface
- if (*ppvObj!=NULL) {
- ((LPUNKNOWN)*ppvObj)->AddRef();
- return NOERROR;
- }
- else {
- return ResultFromScode(E_NOINTERFACE);
- }
- }
-
- ULONG Deformer::AddRef(THIS) {
- return fCRef++;
- }
-
- ULONG Deformer::Release(THIS) {
- ULONG UnreleaseObject=fCRef--;
-
- if (fCRef==0)
- delete this; // No reference left, so destroy the object
-
- return UnreleaseObject;
- // local variable used, because fCRef can be destroyed before.
- }
-
- // I3DExtension methods :
- I3DExtension* Deformer::Clone(THIS) {
- Deformer* theClone = new Deformer;
- if (theClone) {
- theClone->AddRef();
- theClone->fData=fData; // copy the DeformerData
- }
- return (I3DExtension*)theClone;
- }
-
- HRESULT Deformer::ShellUtilitiesInit(THIS_ IShUtilities* shellUtilities) {
- InitCoFailure(shellUtilities);
- return NOERROR;
- }
-
- // I3DExDataExchanger methods :
- ExtensionDataMap* Deformer::GetExtensionDataMap(THIS) {
- return NULL;
- }
-
- void* Deformer::GetExtensionDataBuffer(THIS) {
- return &fData; // used by the shell to set the new parameters
- }
-
- HRESULT Deformer::ExtensionDataChanged(THIS) {
- return NOERROR;
- }
-
- HRESULT Deformer::HandleEvent(THIS_ ULONG SourceID) {
- return ResultFromScode(E_NOTIMPL);
- }
-
- short Deformer::GetResID(THIS) {
- return 140; // this is the view ID in the resource file.
- }
-
- // I3DExDeformer methods :
-
- HRESULT Deformer::SetBBox(THIS_ BOX3D *bbox) {
- fData.fBoundingBox=*bbox;
- return NOERROR;
- }
-
- HRESULT Deformer::DeformPoint(THIS_ VECTOR3D* point,VECTOR3D* result) {
- short u,v,w;
- NUM3D wrelative;
- if(fData.fAxis==kAxisX) {
- u=1; // Y Axis
- v=2; // Z Axis
- w=0; // X Axis
- }
- else if (fData.fAxis==kAxisY) {
- u=2; // Z Axis
- v=0; // X Axis
- w=1; // Y Axis
- }
- else {
- u=0; // X Axis
- v=1; // Y Axis
- w=2; // Z Axis
- }
- if ((fData.fBoundingBox.fMax[w]-fData.fBoundingBox.fMin[w])==0.0) {
- (*result)[0]=(*point)[0];
- (*result)[1]=(*point)[1];
- (*result)[2]=(*point)[2];
- return NOERROR;
- }
- wrelative=((*point)[w] - fData.fBoundingBox.fMin[w])/(fData.fBoundingBox.fMax[w]-fData.fBoundingBox.fMin[w]);
- if ((fData.fUEndScale+fData.fUBegScale)==0.0) {
- (*result)[u]=0.0;
- }
- else {
- (*result)[u] = (*point)[u] * (fData.fUBegScale + wrelative * (fData.fUEndScale-fData.fUBegScale));
- }
- if ((fData.fVEndScale+fData.fVBegScale)==0.0) {
- (*result)[v]=0.0;
- }
- else {
- (*result)[v] = (*point)[v] * (fData.fVBegScale + wrelative * (fData.fVEndScale-fData.fVBegScale));
- }
- (*result)[w] = (*point)[w];
- return NOERROR;
- }
-
- HRESULT Deformer::DeformFacetMesh(THIS_ NUM3D lod,const FacetMesh &in,FacetMesh &out) {
- return ResultFromScode(E_NOTIMPL);
- }
-
- HRESULT Deformer::DeformBBox(THIS_ const BOX3D &in,BOX3D &out) {
- const VECTOR3D *borne[2];
- VECTOR3D point, deformed;
- borne[0]=&in.fMin;
- borne[1]=&in.fMax;
- int ii, jj, kk, ll;
- out=in;
- for (ii=1; ii>=0; ii--) {
- point[0]=(*borne[ii])[0];
- for (jj=1; jj>=0; jj--) {
- point[1]=(*borne[jj])[1];
- for (kk=1; kk>=0; kk--) {
- point[2]=(*borne[kk])[2];
- DeformPoint(&point, &deformed);
- for (ll=2; ll>=0; ll--) {
- if (deformed[ll] < out.fMin[ll]) out.fMin[ll]=deformed[ll];
- if (deformed[ll] > out.fMax[ll]) out.fMax[ll]=deformed[ll];
- }
- }
- }
- }
-
- // (damien) the BBox is not necessarely the one of the deformed object
- // it can be the bbox of a child of this object
- // the following code is then wrong.
- /*
- NUM3D maxU=(fData.fUBegScale > fData.fUEndScale) ? fData.fUBegScale : fData.fUEndScale;
- NUM3D maxV=(fData.fVBegScale > fData.fVEndScale) ? fData.fVBegScale : fData.fVEndScale;
- out.fMin[0]=in.fMin[0]*maxU;
- out.fMin[1]=in.fMin[1]*maxV;
- out.fMin[2]=in.fMin[2];
- out.fMax[0]=in.fMax[0]*maxU;
- out.fMax[1]=in.fMax[1]*maxV;
- out.fMax[2]=in.fMax[2];
- */
- return S_OK;
- }
-